// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { Palette, ScrollView }  from "std-widgets.slint";

import { ExpandableGroup } from "../components/expandable-group.slint";

import { Api, ElementInformation, PropertyGroup, PropertyInformation } from "../api.slint";
import { EditorSpaceSettings, EditorSizeSettings } from "../components/styling.slint";

import { PropertyInformationWidget } from "../components/property-widgets.slint";

export component PropertyView inherits ScrollView {

    property <ElementInformation> element-information <=> Api.current-element;
    property <[PropertyGroup]> properties <=> Api.properties;

    property <length> key-width: self.width / 2.5;
    property <bool> element-loaded: root.properties.length > 0;

    vertical-scrollbar-policy: ScrollBarPolicy.always-on;

    content-layer := VerticalLayout {
        if !root.element-loaded: Text {
            text: @tr("Select an Element");
            horizontal-alignment: center;
            vertical-alignment: center;
            vertical-stretch: 1;
        }
        if root.element-loaded: groups := VerticalLayout {
            alignment: start;

            for group in root.properties: eg := ExpandableGroup {
                property <[PropertyInformation]> properties: group.properties;

                enabled: root.enabled;

                text: group.group-name;
                panel-width: root.width;

                VerticalLayout {
                    spacing: EditorSpaceSettings.property-spacing;
                    padding: EditorSpaceSettings.default-padding;

                    for property in eg.properties: PropertyInformationWidget {
                        enabled: root.enabled;
                        element-information <=> root.element-information;
                        property-information: property;
                    }
                }
            }
        }
    }
}

